<?php

namespace App\Console\Commands;

use App\Models\UserInfos;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;

class Meeting extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:meeting';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // 当前时间戳
        $time = time();
        $data = \App\Models\Meeting::all()->toArray();
        foreach ($data as $val){
            if ($val['begin_time']+60*15>=$time){
                // 获取会议号
                $meeting_num = UserInfos::where('id',$val['user_id'])->first()->toArray()['meeting_num'];
                // 判断会议是否有人进入    这个缓存是在用户进入会议的时候进行一个缓存
                if (empty(Cache::get("$meeting_num".'num'))){
                    // 30分钟内没有人进入会议  关闭会议  修改会议状态
                    \App\Models\Meeting::where('meeting_num',$meeting_num)->update(['state'=>2]);
                }
            }
        }
    }
}
